/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fjnu.dao;

import fjnu.dao.factory.IMapper;
import java.util.Vector;

/**
 *=============================
 * @author neco
 * 2012 09 11 15:34 创建
 * 基类
 * ===============================
 */
public abstract class AbstractObject {

    private String Supplier;
    private float Price;
    private String Type;
    private boolean changed = false;
    private Vector obs;
    private int ID;
    private int _Broken = 0;
    private java.util.Date BuyTime;
    public final static String TAG="AbstractObject";
    /**
     * Get the value of BuyTime
     *
     * @return the value of BuyTime
     */
   public String  getBuyTime() {
        return BuyTime.toString();
    }

    /**
     * Set the value of BuyTime
     *
     * @param BuyTime new value of BuyTime
     */
    
    public void setBuyTime(java.util.Date BuyTime) {
        this.BuyTime = BuyTime;
    }

    public AbstractObject() {
        obs = new Vector();
    }

    public synchronized void addMapper(IMapper o) {
        if (o == null) {
            throw new NullPointerException();
        }
        if (!obs.contains(o)) {
            obs.addElement(o);
        }
    }

    public synchronized void deleteMapper(IMapper o) {
        obs.removeElement(o);
    }

    public void notifyMapperBroken() {
        notifyMapperBroken(null);
    }

    public void notifyMapperFix() {
        notifyMapperFix(null);
    }

    public void notifyMapperFix(Object arg) {
        Object[] arrLocal;
        synchronized (this) {
            if (!changed) {
                return;
            }
            arrLocal = obs.toArray();
            clearChanged();
        }
        for (int i = arrLocal.length - 1; i >= 0; i--) {
            ((IMapper) arrLocal[i]).fix(this, arg);
        }
    }

    public void notifyMapperBroken(Object arg) {
        Object[] arrLocal;
        synchronized (this) {

            if (!changed) {
                return;
            }
            arrLocal = obs.toArray();
            clearChanged();
        }
        for (int i = arrLocal.length - 1; i >= 0; i--) {
            ((IMapper) arrLocal[i]).broken(this, arg);
        }
    }

    public synchronized void deleteMapper() {
        obs.removeAllElements();
    }

    protected synchronized void setChanged() {
        changed = true;
    }

    protected synchronized void clearChanged() {
        changed = false;
    }

    public synchronized boolean hasChanged() {
        return changed;
    }

    public synchronized int countMapper() {
        return obs.size();
    }

    /**
     * Get the value of supplier
     *
     * @return the value of supplier
     */
    public String getSupplier() {
        return Supplier;
    }

    /**
     * Set the value of supplier
     *
     * @param supplier new value of supplier
     */
    public void setSupplier(String supplier) {
        this.Supplier = supplier;
    }

    /**
     * Get the value of Price
     *
     * @return the value of Price
     */
    public float getPrice() {
        return Price;
    }

    /**
     * Set the value of Price
     *
     * @param Price new value of Price
     */
    public void setPrice(float Price) {
        this.Price = Price;
    }

    /**
     * Get the value of Type
     *
     * @return the value of Type
     */
    public String getType() {
        return Type;
    }

    /**
     * Set the value of Type
     *
     * @param Type new value of Type
     */
    public void setType(String Type) {
        this.Type = Type;
    }

    /**
     * Get the value of ID
     *
     * @return the value of ID
     */
    public int getID() {
        return ID;
    }

    /**
     * Set the value of ID
     *
     * @param ID new value of ID
     */
    public void setID(int ID) {
        this.ID = ID;
    }

    /**
     * Get the value of _Broken
     *
     * @return the value of _Broken
     */
    public int get_Broken() {
        return _Broken;
    }

    /**
     * Set the value of _Broken
     *
     * @param _Broken new value of _Broken
     */
    public void set_Broken(int _Boken) {
        this._Broken = _Boken;
    }

    public void repair() {
        this._Broken++;
        setChanged();
        notifyMapperBroken();
    }

    public void fix() {
        this._Broken = 0;
        setChanged();
        notifyMapperFix();
    }
}
